package com.paomi.client.activity.person;

import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.hannesdorfmann.mosby3.mvp.MvpView;
import com.paomi.client.R;
import com.paomi.client.activity.person.View.InvitationView;
import com.paomi.client.activity.person.presenter.InvitationPre;
import com.paomi.client.base.BaseMvpActivity;
import com.paomi.client.bean.OnlyIntBean;
import com.paomi.client.bean.OnlyStringBean;
import com.paomi.client.net.Constants;
import com.paomi.client.utils.Util;
import com.paomi.client.view.ShareDialog;

import butterknife.BindView;
import butterknife.OnClick;
import cn.sharesdk.tencent.qq.QQ;
import cn.sharesdk.wechat.friends.Wechat;

public class InvitationActivity extends BaseMvpActivity<InvitationView, InvitationPre> implements ShareDialog.dialogClick, InvitationView {
    @BindView(R.id.button_goback)
    TextView button_goback;
    @BindView(R.id.tv_invitation)
    TextView tv_invitation;
    private String getCode;

    @NonNull
    @Override
    public InvitationPre createPresenter() {
        return new InvitationPre();
    }

    @Override
    protected String setTitle() {
        return getResources().getString(R.string.string_my_invitation);
    }

    @Override
    protected void showBack(TextView button_goback) {
        button_goback.setVisibility(View.VISIBLE);
    }

    @NonNull
    @Override
    protected int getLayoutId() {
        return R.layout.activity_invitation;
    }

    @Override
    protected void initEvent() {
        button_goback.setTypeface(iconfont);
        button_goback.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
        button_goback.setTextColor(getResources().getColor(R.color.main_color));
        button_goback.setText(getResources().getString(R.string.back_normal) + getResources().getString(R.string.back));


        getPresenter().getCode();
        getPresenter().getCount();
    }

    @OnClick(R.id.tv_btn)
    void toClick() {
        new ShareDialog(this, this).creat().show();
    }

    @Override
    public void qqClick() {//qq分享
        getPresenter().showShare(this, QQ.NAME, getCode);
    }

    @Override
    public void qzClick() {//复制
        //http://test.h5.opentickets.cn/invitation.html
        //获取剪贴板管理器：
        ClipboardManager cm = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
        // 创建普通字符型ClipData
        ClipData mClipData = ClipData.newPlainText("Label", Constants.HTML_INVITATION);
        // 将ClipData内容放到系统剪贴板里。
        cm.setPrimaryClip(mClipData);

    }

    @Override
    public void wxClick() {//微信分享
        getPresenter().showShare(this, Wechat.NAME, getCode);

    }

    @Override
    public void wbClick() {

    }

    @Override
    public void pyqClick() {

    }

    @Override
    public void showCode(OnlyStringBean bean) {
        if (bean.returnCode.equals("0000")) {
            getCode = bean.getReturnData();
        } else {
            Util.toast(this, bean.returnMessage);
        }
    }

    @Override
    public void showNum(OnlyIntBean bean) {
        if (bean.returnCode.equals("0000")) {
            tv_invitation.setText(getResources().getString(R.string.invitation_msg_left) + bean.getReturnData() + getResources().getString(R.string.invitation_msg_right));
        } else {
            Util.toast(this, bean.returnMessage);
        }
    }
}
